//--------------------------------------------------------------
//	Company:	HTHK
//	NAME:	    ChangeNum.java
//	TITLE:	    Change the num form
//	FUNCTION:	To change the number form
//	BY:	        Kodak Xu
//	DATE:	    28/08/2003
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  Kodak Xu   DATE:  17/09/2003
//	ERROR:	when str is null can't substring;
//	FIX:	when str is null return "";
// --------------------------------------------------------------

package tss.options;

import org.apache.log4j.Logger;

public class ChangeNum
{
	private static Logger logger = Logger.getLogger(ChangeNum.class);
	public static String toInt(String str)
	{
		try
			{
				if (str.length()==0)
					return str="";
				else if (str.indexOf('.')==-1)
					return str;
				else
				    return str = str.substring(0,str.indexOf('.'));
			}catch(Exception e) {
				logger.error(e,e);
				return str ;
			}
	}

	public String getFixNum(String num,int dec)
	{
		String str = "";
		if (num==null || num.length()==0)
			str="";
		else if(num.indexOf('.')==-1)
		{
			str = num+".";
			for(int i=1;i<=dec;i++)
				str += "0";
		}
		else
		{
			str = num.substring(0,num.indexOf('.')+1);
			int strlength = str.length();
			if ((num.length()-strlength)<dec)
			{
				str = num;				
				for(int i=1;i<=dec-(num.length()-strlength);i++)
					str += "0";
				
			}
			else
				str = num.substring(0,num.indexOf('.')+dec+1);
		}
			
		return str;
	}
}
